﻿// STL.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//


#include<iostream>
#include<vector>
#include <string.h>
#include<algorithm>
#include<list>

using namespace std;
/////标准库
////容器 迭代器
////删除，插入较为频繁的操作选用 链表，缺点是不能随机访问  O(1) 常数阶
////
void main()
{
	list<int> v;

}
/*void main()
{
	vector<int> v;
	for(int i=1;i<=8;i++)
	{
		v.push_back(i);
	}
	vector<int >::iterator it = v.begin();
	v.erase(++it);
	it = v.begin();
	while(it !=v.end())
	{
		cout<<*it<<",";
		++it;
	}
	reverse(v.begin(),v.end());
	cout<<endl;
	it = v.begin();
	while(it !=v.end())
	{
		cout<<*it<<",";
		++it;
	}

}
void main()
{
	vector<int> v;
	for(int i=1;i<=8;i++)
	{
		v.push_back(i);
	}
	cout<<"size:"<<v.size()<<endl;
	cout<<"capicity:"<<v.capacity()<<endl;
	vector<int>::iterator it = v.begin();
	++it;
	cout<<"*it="<<*it<<endl;
	///////引发空间重新分配
	cout<<"****************"<<endl;
	////////////////////////////
	//1 2 3 4 5 6 7 8
	v.push_back(9);

	//size:8
	//capicity:8
	//*it=2
	//*it=-572662307  迭代器失效
	//Press any key to continue
	///重新计算迭代器
	it=v.begin();
	++it;
	cout<<"*it="<<*it<<endl;
}

void main()
{
	vector<int> v;
	for(int i=1;i<=10;i++)
	{
		v.push_back(i);
	}
	for(int k=0;k<v.size();k++)
	{
		cout<<v[k]<<",";
	}
	//////////
	//1  2 3 4 5 6 7 8 9 10
	//
	//插入方法，删除方法  iterator迭代器是否有效



	cout<<endl;
	vector<int>::iterator it1 = v.begin()+6;//7
	vector<int>::iterator it2 = v.begin()+8;//9


	vector<int> v1;
	v1.assign(it1,it2);

	vector<int>::iterator it;
	it = v1.begin();
	++it;
	v1.insert(it,it1,it2);

	it =v1.begin();
	for(;it != v1.end(); ++it)
	{
		cout<<*it<<",";

	}
	cout<<endl;
	return;
}



using namespace std;

bool compare(int a,int b)
{
	return a<b;//升序排列n
}
void main()
{
	int a[20] = {1,45,67,8,34,6776,878,98,3,4,34,324,90};
	for(int i=0;i<20;i++)
	{
		cout<<a[i]<<",";
	}
	cout<<endl;
	sort(a,a+20);
	for(int k=0;k<20;k++)
		cout<<a[k]<<",";
	cout<<endl;
}

void main()
{
	vector<int> obj;
	obj.push_back(1);
	obj.push_back(7);
	obj.push_back(8);
	obj.push_back(4);
	cout<<"从小到大:->";
	sort(obj.begin(),obj.end());
	for(int i=0;i<obj.size();i++)
	{
		cout<<obj[i]<<",";
	}
	cout<<endl;
	cout<<"从大到小:->";
	reverse(obj.begin(),obj.end());
	for(int k=0;k<obj.size();k++)
	{
		cout<<obj[k]<<",";
	}
	cout<<endl;



}








/////////////////////////////////////////////
///插入

void main()
{
	vector<int> obj;
	for(int i=0;i<=10;i++)
	{
		obj.push_back(i);
		cout<<obj[i]<<",";
	}
	cout<<endl;
	for(int j=0;j<5;j++)//去掉数组最后一个数据
	{
		obj.pop_back();

	}
	for(int k=0;k<obj.size();k++)
	{
		cout<<obj[k]<<",";
	}
	cout<<endl;
}

void main()
{

	vector<int> v;
	//vector(int nSize):创建一个vector,元素个数为nSize
	vector<int> v0(11);
	cout<<"v0.size()="<<v0.size()<<endl;
	//vector(int nSize,const t& t):创建一个vector，元素个数为nSize,且值均为t
	vector<int> v1(10,1);
	vector<int>::iterator it1 = v1.begin();
	cout<<"it1.size()="<<v1.size()<<endl;
	cout<<"it1 = ";
	while(it1 != v1.end())
	{
		cout<<*it1<<" ";
		it1++;
	}
	cout<<endl;
	int ar[10] = {1,2,3,4,5,6,7,8,9,10};
	vector<int> v2(ar,ar+10);
	//vector(begin,end):复制[begin,end)区间内另一个数组的元素到vector中
	vector<int>::iterator it2 = v2.begin();
	cout<<"v2.size()="<<v2.size()<<endl;
	while(it2 !=v2.end())
	{
		cout<<*it2<<" ";
		it2++;
	}
	cout<<endl;

	vector<int> v3(10,100);
	int count = 0;
	count = v2.max_size();
	cout<<"count = v2.max_size()"<<count<<endl;
//	v3.reserve(10);
	vector<int>::iterator it3 = v3.begin();
	cout<<"it3.size()="<<v3.size()<<endl;
	cout<<"it3 = ";

	while(it3 != v3.end())
	{
		cout<<*it3<<" ";
		it3++;
	}
	cout<<endl;
}*/
/*void main()
{
	vector<int> v;
	for (int i = 1; i <= 10; ++i)
	{
		v.push_back(i);
	}
	
	cout<<"v.at(5) = "<<v.at(5) << endl;
	//////容量只能往上预留
	//v.reserve(17);
	//0)v.size()=10
	//v.capicity() = 13
	//	1 2 3 4 5 6 7 8 9 10
	
	//1)v.reserve(100);
	//v.size() = 10
	//v.capicity() = 100
	//1 2 3 4 5 6 7 8 9 10
	//
	//2)v.resize(100);
	//v.size() = 100
	//v.capicity() = 100
	//1 2 3 4 5 6 7 8 9 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
	cout << "v.size()=" << v.size()<<endl;
	cout << "v.capicity()=" << v.capacity()<<endl;
	//////insert (i,x) pos iterator ++ -- 每一个容器里面都有自己的迭代器
	//插入删除的位置iterator   迭代器位置的前面插入删除
	//效率
	//尾删
	//v.pop_back();
	//v.pop_back();
	//v.pop_back();
	//头删  v.push_front
	//cout<<"v.front() = "<<v.front()<<endl;
	//cout << "v.back() = " << v.back() << endl;

	vector<int>::iterator it = v.begin();
	while (it != v.end())
	{
		cout << *it << " ";
		it++;
	}
	return;

}
void main()
{   //////////////////////////////////////////////////////////////////////////////////////////////////////
	//*2倍
	vector<int> v;
	v.push_back(1);
	v.push_back(2);
	v.push_back(3);
	v.push_back(4);
	v.push_back(5);
	cout << "v.size()=" << v.size() << endl;
	cout << "v.capacity()=" << v.capacity() << endl;
}




*/

